import { StorageEnum } from '@/types/enum';
import { create } from 'zustand';
import { persist } from 'zustand/middleware';

type TourStore = {
  isTourStart: boolean;
  isTourGuide: boolean;
  isUserClick: boolean;
  isFirstLogin: boolean;
  actions: {
    setIsTourStart: (flag: boolean) => void;
    setIsTourGuide: (flag: boolean) => void;
    setIsUserClick: (flag: boolean) => void;
    setIsFirstLogin: (flag: boolean) => void;
  };
};

const useTourStore = create(
  persist<TourStore>(
    (set) => ({
      isTourStart: false,
      isTourGuide: false,
      isUserClick: false,
      isFirstLogin: false,
      actions: {
        setIsTourStart: (params) => set({ isTourStart: params }),
        setIsTourGuide: (params) => set({ isTourGuide: params }),
        setIsUserClick: (params) => set({ isUserClick: params }),
        setIsFirstLogin: (params) => set({ isFirstLogin: params }),
      },
    }),
    {
      name: StorageEnum.TourStorage,
      partialize: (state) => ({ isFirstLogin: state.isFirstLogin }),
    }
  )
);


export const useTourActions = () => useTourStore((state) => state.actions);
export const useIsTourStart = () => useTourStore((state) => state.isTourStart);
export const useIsTourGuide = () => useTourStore((state) => state.isTourGuide);
export const useIsUserClick = () => useTourStore((state) => state.isUserClick);
export const useIsFirstLogin = () => useTourStore((state) => state.isFirstLogin);

export default useTourStore;